home *** CD-ROM | disk | FTP | other *** search
/ 100 Plus Great Games 2 / 100PLUSV2.BIN / games / AboveBelow.dxr / Internal_5_stock cards.ls < prev    next >
Encoding:
Text File  |  2002-01-25  |  1.9 KB  |  63 lines

  1. property spriteNum, wastecard
  2. global stock, waste, redeals
  3.  
  4. on beginSprite me
  5.   redeals = 0
  6.   stock = new(script("card pile"))
  7.   stock.cards = shuffle()
  8.   wastecard = sprite(12)
  9. end
  10.  
  11. on mouseDown me
  12.   if sprite(spriteNum).member = member("backofcard", "playing cards") then
  13.     puppetSound(3, member("deal card", "100GPak Generic SFX"))
  14.     wastecard.member = member(stock.cards[1].rank & "_" & stock.cards[1].suit, "playing cards")
  15.     stock.cards.deleteAt(1)
  16.     waste.addCard(wastecard.spriteNum)
  17.     if stock.getcardcount() = 0 then
  18.       if redeals < 1 then
  19.         sprite(spriteNum).member = member("replenish", "playing cards")
  20.       else
  21.         sprite(spriteNum).member = member("empty", "playing cards")
  22.         checklose()
  23.       end if
  24.     end if
  25.   else
  26.     if sprite(spriteNum).member = member("replenish", "playing cards") then
  27.       stock.cards = reshuffle(waste.cards)
  28.       waste.cards.deleteAll()
  29.       wastecard.member = member("empty", "playing cards")
  30.       wastecard.undercard.member = wastecard.member
  31.       redeals = redeals + 1
  32.       sprite(spriteNum).member = member("backofcard", "playing cards")
  33.     end if
  34.   end if
  35. end
  36.  
  37. on shuffle me
  38.   ranks = ["ace", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "jack", "queen", "king"]
  39.   suits = ["hearts", "diamonds", "clubs", "spades"]
  40.   unshuffledCards = []
  41.   shuffledCards = []
  42.   repeat with i = 1 to 2
  43.     repeat with rank in ranks
  44.       repeat with suit in suits
  45.         unshuffledCards.add([#rank: rank, #suit: suit])
  46.       end repeat
  47.     end repeat
  48.   end repeat
  49.   repeat while unshuffledCards.count > 0
  50.     shuffledCards.add(unshuffledCards[random(unshuffledCards.count)])
  51.     unshuffledCards.deleteOne(shuffledCards[shuffledCards.count])
  52.   end repeat
  53.   return shuffledCards
  54. end
  55.  
  56. on reshuffle arg
  57.   sho = []
  58.   repeat with i = 1 to arg.count
  59.     sho.add([#rank: arg[i].rank, #suit: arg[i].suit])
  60.   end repeat
  61.   return sho
  62. end
  63.